package com.zqcy.workbench.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.onemdos.scan.ScanUtils;
import com.shinemo.base.core.utils.ToastUtil;
import com.zqcy.workbench.R;
import com.zqcy.workbench.utils.Utils;

import java.util.Random;

/**
 * 收付款页面
 */
public class PaymentCodeActivity extends AppCompatActivity {

    private ImageView codeImg;

    public static void startActivity(Context context) {
        Intent starter = new Intent(context, PaymentCodeActivity.class);
        context.startActivity(starter);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_payment_code);

        initView();
        createCode();
    }

    private void createCode() {
        Random random = new Random();
        String content = random.nextInt(10000) + "";
        Log.e("createCode -> ", content);
        Bitmap resultImage = ScanUtils.genQrCodeBitmap(content, 1, Color.BLACK, Color.WHITE, 240, 240);
        if (resultImage == null) {
            ToastUtil.show(PaymentCodeActivity.this, "生成二维码失败");
        } else {
            codeImg.setImageBitmap(resultImage);
        }
    }

    private void initView() {
        Utils.setColor(this, getResources().getColor(R.color.c_bg_2));
        codeImg = findViewById(R.id.code_img);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    public void onBack(View view) {
        finish();
    }
}